package Exercise;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class Exercise1 {

    public static void testSeleteDept() throws SQLException {
        Connection connection = null;
        try {
            Class.forName("oracle\"oracle.jdbc.driver.OracleDriver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        try {
            DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE", "scott", "tiger");
        } catch (SQLException e) {
            e.printStackTrace();
        }
        try {
            connection.createStatement();
            String sql = "insert into emp values(7781,?,?,?,?,?,?,?)";
            int result = connection.createStatement().executeUpdate(sql);
            if (result > 0) {
                System.out.println("添加成功");
            } else {
                System.out.println("添加失败");
            }

        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            if (connection.createStatement() != null) {
                try {
                    connection.createStatement().close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
            if (connection != null) {
                    try {
                        connection.close();
                    } catch (SQLException e) {
                        e.printStackTrace();
                    }

            }
        }
    }
    public static void main (String[]args){
        try {
            testSeleteDept();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}




